package com.ruitu.mall_98_2.mvp.presenter;

import com.beanu.arad.utils.ToastUtils;
import com.ruitu.mall_98_2.mvp.contract.CouponContract;
import com.ruitu.router_module.bean.api.BaseResult;
import com.ruitu.router_module.bean.api.SubscriberImpl;
import com.ruitu.router_module.bean.mine.Coupon;

import java.util.List;

public class CouponPresenter extends CouponContract.Presenter {
    @Override
    public void getMineCouponsNew(String accountId, String mode) {
        mModel.getMineCouponsNew(accountId, mode)
                .subscribe(new SubscriberImpl<BaseResult<List<Coupon>>>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("获取优惠券失败");
                        mView.setFail();
                    }

                    @Override
                    public void onNext(BaseResult<List<Coupon>> couponBaseResult) {
                        mView.hideProgress();
                        if (couponBaseResult.isSuccess()) {
                            mView.setData(couponBaseResult.getData());
                        }
                    }
                });
    }
}
